package com.xhwl.data.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.dto.cent.sdata.OrganizationDTO;
import com.xhwl.common.pojo.cent.sdata.Organization;
import com.xhwl.common.query.cent.sdata.OrganizationQuery;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @description: 组织
 * @author:
 * @create: 2020-11-25
 **/
@Repository
public interface IOrganizationDao extends BaseMapper<Organization> {


    default List<Organization> all() {
        return this.selectList(null);
    }

    List<Organization> list(@Param("orgQuery") OrganizationQuery organizationQuery);

    Organization one(@Param("orgQuery") OrganizationQuery organizationQuery);

    /**
     * 检查编码是否唯一
     *
     * @param dto
     * @return
     */
    @Select("<script>select ifnull(count(id),0) from `cent_sdata`.`sdata_organization` " +
            "where `is_deleted` = 0 and `code` = #{dto.code} " +
            "and `type` = #{dto.type} and `project_id` = #{dto.projectId} " +
            "<if test=\" dto.id !=null  \"> and `id` != #{dto.id}</if></script>")
    Integer checkUniqueCode(@Param("dto") OrganizationDTO dto);

    Page<Organization> orgPage(Page page,@Param("projectIds") List<Integer> projectIds,@Param("types")List<Integer> types);
}
